package com.wtwd.device.service.impl;


import com.baomidou.mybatisplus.extension.conditions.query.LambdaQueryChainWrapper;
import com.wtwd.device.dao.StepMapper;
import com.wtwd.device.model.entity.Step;
import com.wtwd.device.service.StepService;
import org.springframework.stereotype.Service;

import javax.annotation.Resource;
import java.util.ArrayList;
import java.util.List;
import java.util.Map;

/**
 * <p>
 * 每日步数 服务实现类
 * </p>
 *
 * @author zdl
 * @since 2021-08-31
 */
@Service
public class StepServiceImpl implements StepService {

    @Resource
    private StepMapper stepMapper;

    @Override
    public boolean save(Step step) {
        return stepMapper.insert(step) == 1;
    }

    @Override
    public Step getByDeviceAndDate(Long deviceId, String date) {
        return new LambdaQueryChainWrapper<>(stepMapper)
                .eq(Step::getDeviceId, deviceId)
                .eq(Step::getTime, date)
                .one();
    }

    @Override
    public List<Step> listByDeviceAndDate(Long deviceId, String startDate, String endDate) {
        return new LambdaQueryChainWrapper<>(stepMapper)
                .eq(Step::getDeviceId, deviceId)
                .between(Step::getTime, startDate, endDate)
                .select(Step::getDeviceId, Step::getTime, Step::getTotalCalories
                        , Step::getTotalDistance, Step::getTotalSteps, Step::getTotalTime)
                .list();

    }

    @Override
    public List<Step> listByDeviceAndMonth(Long deviceId, String month) {
        return new LambdaQueryChainWrapper<>(stepMapper)
                .eq(Step::getDeviceId, deviceId)
                .likeRight(Step::getTime, month)
                .select(Step::getDeviceId, Step::getTime, Step::getTotalCalories
                        , Step::getTotalDistance, Step::getTotalSteps, Step::getTotalTime)
                .list();
    }

    @Override
    public Integer clearStepByDate(String date) {
        return stepMapper.clearStepByDate(date);
    }

    @Override
    public List<Map<String, Object>> getStepInfoByUserIdList(ArrayList<Long> friendIdList, String yestTime) {
        return stepMapper.getStepInfoByUserIdList(friendIdList, yestTime);
    }

    @Override
    public Step getStepInfoByDeviceIdAndTime(Long id, String time) {
        return stepMapper.getStepInfoByDeviceIdAndTime(id,time);
    }

    @Override
    public Step getDayMaxStepByDeviceId(Long deviceId) {
        return stepMapper.getDayMaxStepByDeviceId(deviceId);
    }

    @Override
    public Integer getTotalStepByDeviceId(Long id) {
        return stepMapper.getTotalStepByDeviceId(id);
    }

    @Override
    public Integer deleteStepByDeviceId(Long id) {
        return stepMapper.deleteStepByDeviceId(id);
    }


}
